<template>
  <div class="tenantMenu_main main_container">
    <div class="main_header">
      <div class="padding_container">
        <div class="left"><Breadcrumb /></div>
        <div class="right">
          <HeaderOperation :parent="this" />
        </div>
      </div>
    </div>
    <div v-loading="loading" class="main_main">
      <search-bar-new :parent="this" />
      <div ref="table_container" class="table_container">
        <el-table
          ref="table"
          :data="tableData"
          stripe
          border
          :height="tableHeight"

          :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
          :cell-style="cellStyle"
          :summary-method="getSummaries"
          :show-summary="true"
          @cell-click="cellClick"
          @sort-change="(column)=>{sortChange(column, this)}"
          @selection-change="(val)=>{selectionChange(val, this)}"
        >
          <el-table-column type="selection" align="center" width="70" />
          <Column
            v-for="(column,index) in tableColumns"
            :key="index"
            :prop="column.prop"
            :is-show="column.isShow"
            :label="column.label"
            :sortable="column.sortable"
            :width="column.width"
            :min-width="column.minWidth"
            :align="column.align"
          />
          <!-- <el-table-column label="库存数量" align="center" width="120">
            <template slot-scope="scope">
              <span>{{ scope.row.stockNum }}</span>
            </template>
          </el-table-column> -->
        </el-table>
      </div>
    </div>
    <div class="main_bottom">
      <pagination
        :total="total"
        :page.sync="pageData.pageNum"
        :limit.sync="pageData.pageSize"
        :selected-num="selectionsAll.length"
        @pagination="getList"
      />
    </div>
  </div>
</template>

<script>
import { list } from '@/api/warehouseManagement/inventoryBatchNumberAccount'
import { getDictSelects } from '@/api/common/common'
export default {
  name: 'Index',
  data() {
    return {
      loading: true,
      pageId: '库存批号账', // 页面唯一标识
      pageExportId: '库存批号账导出', // 页面导出标识
      pageData: {
        pageNum: 1,
        pageSize: 20,
        orderByColumn: 'materialCode',
        isAsc: 'asc'
      },
      // tableKey: 1,
      total: 1, // 数据一共有多少条
      mainId: 'id', // 表格行ID
      tableHeight: '0', // 表格高度
      tableData: [], // 表格数据
      tableColumns: [], // 表格实际用的字段
      searchColumns: [], // 搜索区实际用的字段
      selections: [], // 表格当前页所选中的行
      selectionsAll: [], // 表格所有页选中的行
      totalWord: ['stockNum'], // 合计导出字段
      defaultTableColumns: [// 表格常规字段（初始值）
        { prop: 'materialCode', label: '物料编码', minWidth: '180', canOrder: true, position: 'left' },
        { prop: 'materialName', label: '物料名称', minWidth: '180', canOrder: false, position: 'left' },
        { prop: 'materialModel', label: '规格型号', canOrder: false, position: 'left' },
        { prop: 'palletBatchCode', label: '批号', canOrder: false },
        { prop: 'materialUnitName', label: '物料单位', canOrder: false },
        { prop: 'stockNum', label: '库存数量', canOrder: true, align: 'right', position: 'right', minWidth: this.SETTINGS.settings_decimalDigits_length }
      ],
      exportTableColumns: [
        { prop: 'materialCode', label: '物料编码', minWidth: '180', canOrder: true, position: 'left' },
        { prop: 'materialName', label: '物料名称', minWidth: '180', canOrder: false, position: 'left' },
        { prop: 'materialModel', label: '规格型号', canOrder: false, position: 'left' },
        { prop: 'palletBatchCode', label: '批号', canOrder: false },
        { prop: 'materialUnitName', label: '物料单位', canOrder: false },
        { prop: 'stockNum', label: '库存数量', canOrder: true, align: 'right', position: 'right', minWidth: this.SETTINGS.settings_decimalDigits_length }
      ],
      defaultExport: [],
      defaultSearchColumns: [// 搜索区常规字段（初始值）
        { prop: 'searchValue', label: '模糊搜索', type: 'input' },
        // { prop: 'materialCode', label: '物料编码', type: 'input' },
        // { prop: 'materialName', label: '物料名称', type: 'input' },
        // { prop: 'materialModel', label: '规格型号', type: 'input' },
        { prop: 'materialUnitId', label: '物料单位', type: 'dict', optionsName: 'materialUnitOptions' }
        // { prop: 'palletBatchCode', label: '批号', type: 'input' }
      ],
      whatWarehouse: [],
      statusOptions: [],
      materialUnitOptions: [],
      descriptionOptions: [],
      Updata: [],
      operationData: [ // 右上角的操作按钮
        { label: '批量导出2', perm: '' },
        { label: '页面配置', perm: '' }
      ]
    }
  },
  created() {
    // this.getStorageList()
  },
  mounted() {
    this.getDictOptions()
  },
  methods: {
    // 物料单位
    getDictOptions() {
      console.log(111)
      getDictSelects('materialUnitId').then(res => {
        this.materialUnitOptions = res.data
      })
      getDictSelects('descriptionId').then(res => {
        this.descriptionOptions = res.data
      })
    },
    cellStyle({ row, column }) {
      if (column.property == 'formCode') {
        return {
          cursor: 'pointer',
          color: '#387bfc'
        }
      }
    },
    cellClick(row, column, cell) {
      switch (column.property) {
        case 'formCode':
          this.showDetail(row)
          break
      }
    },
    // 导出
    getExportData(data) {
      return new Promise(function(resolve, reject) {
        list(data).then(res => {
          resolve(res.data.data)
        })
      })
    },
    getList() {
      console.log(this.pageData)
      //   this.pageData.orderByColumn = 'updateTime'
      list(this.pageData).then(res => {
        this.tableData = res.data.data
        this.total = res.data.total
        this.Updata = res
        this.loading = false
        this.$nextTick(() => {
          this.setSelectRow(this)// 设置行选中
          this.tableHeight = this.$refs.table_container.offsetHeight
          this.$refs.table.doLayout()
        })
      })
    },
    // 合计行
    getSummaries(param) {
      console.log(param)
      const {
        columns
      } = param
      const sums = []
      columns.forEach((column, index) => {
        if (index == 0) {
          sums[index] = '合计'
          return
        }
        switch (column.label) {
          case '库存数量':
            sums[index] = this.Updata.allNums
            break
        }
      })
      return sums
    }
  }
}
</script>

<style lang="less" scoped>
/deep/.el-table__fixed-footer-wrapper tbody td.el-table__cell{
  border: none !important;
  background-color: transparent!important;
}
/deep/ .el-table__footer-wrapper tbody td.el-table__cell{
  background-color: rgba(0,0,0,0);
}
/deep/ .el-table__footer-wrapper tbody td.el-table__cell{
  background-color: transparent!important;
}
/deep/ .el-table th.el-table__cell.is-leaf, .el-table td.el-table__cell {
  border-bottom: 1px solid #dfe6ec;
}

/deep/.el-table th.el-table__cell>.cell{
  padding-right: 15%;
}
/deep/.el-table .cell{
  padding-right: 15%;
}
</style>
